//学生成绩排序

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

struct student 
{
	char name[21];
	int grade;
};


int main()
{
	//变量区
	char c,str[21];
	struct student unit[100];
	int temp=0,numofpeople=0;
	int k=0;
	
	//输入区
	scanf("%d",&numofpeople);
	getchar();
	for ( int i=0 ; i<numofpeople ; i++ )
	{
		memset(unit[i].name , '\0' , sizeof(unit[i].name) );
	}
	for ( int j=0 ; j<numofpeople ; j++ )
	{
		k=0;
		c=getchar();
		while ( c != ',')
		{
			unit[j].name[k++] = c;
			c=getchar();
		}
		scanf("%d",&unit[j].grade);
		getchar();
	}
	
	for ( int i=0 ; i<numofpeople-1 ; i++ )
	{
		for ( int j=numofpeople-1 ; j>i ; j-- )
		{
			if ( unit[j].grade > unit[j-1].grade )
			{
				temp = unit[j-1].grade;
				unit[j-1].grade = unit[j].grade;
				unit[j].grade = temp;
				strcpy ( str , unit[j-1].name );
				strcpy ( unit[j-1].name , unit[j].name );
				strcpy ( unit[j].name , str );
			}
		}
	}
	
	for ( int i=0 ; i<numofpeople ; i++ )
	{
		printf("%s,%d\n",unit[i].name,unit[i].grade);
	}
	
	
	return 0;
}